﻿// Genius
// Copyright (C) 2016 Dirk Friedenberger, www.frittenburger.de
//   
// This source file is subject to the Microsoft Public License (Ms-PL).
// http://www.opensource.org/licenses/ms-pl.html
// All other rights reserved.
using System.Configuration;
using System.ServiceProcess;
using Genius.SlackBot.Shared.Locator;
using System.Threading;

namespace Genius.Slackbot.WindowsService
{
    public partial class SlackBotService : ServiceBase
    {
        private Thread runner;

        public SlackBotService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            runner = new Thread(() => {
                var path = ConfigurationManager.AppSettings["path"];
                var bot = SlackBotLocator.GetSlackBot(path);

                bot.Start();
            });

            runner.Start();
        }

        protected override void OnStop()
        {
            runner.Abort();
        }
    }
}
